//
//  YKNewFatureCell.m
//  youkan
//
//  Created by mac mini on 16/2/27.
//  Copyright © 2016年 Honsintech. All rights reserved.
//

#import "YKNewFatureCell.h"
#import "YKTabBarController.h"
@interface YKNewFatureCell()
@property(nonatomic,weak)UIImageView *imageView;    //!> 内容图片
@property(nonatomic,weak)UIButton    *shareButton;     //!> 分享按钮
@property(nonatomic,weak)UIButton    *startButton;     //!> 开始按钮
@end
@implementation YKNewFatureCell
/** 懒加载开始按钮 */
-(UIButton *)shareButton{
    if (!_shareButton) {
        UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:@"分享给大家" forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateSelected];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateNormal];
        [btn sizeToFit];
//        [btn setBackgroundColor:[UIColor greenColor]];
        [self.contentView addSubview:btn]; //!> 因为contentView有对btn引用，所以可以用weak属性
        _shareButton =btn;
    }
    return _shareButton;
}
-(UIButton *)startButton{
    if (!_startButton) {
        UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:@"开始微博" forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
        [btn sizeToFit];
        [btn setBackgroundColor:[UIColor greenColor]];
        [btn addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:btn];
        _startButton =btn;
    }
    return _startButton;
}
-(UIImageView *)imageView{
    if (!_imageView) {
        UIImageView *imageV=[[UIImageView alloc]init];
        _imageView = imageV;
        [self.contentView addSubview:imageV];
    }
    return _imageView;
}
/** 布局子控件 */
-(void)layoutSubviews{
    [super layoutSubviews];
    self.imageView.frame = self.bounds;
    self.shareButton.center =CGPointMake(self.width*0.5, self.height*0.8);
    self.startButton.center =CGPointMake(self.width*0.5, self.height*0.9);
}
-(void)setImage:(UIImage *)image{
    _image = image;
    self.imageView.image = image;
}
/** 点击cell上面的开始按钮
    更换主Window的根控制器
 */
-(void)start{
    YKTabBarController *tabBarVC =[[YKTabBarController alloc]init];
    YKKeyWindow.rootViewController =tabBarVC; //!> 设置根控制器
}
/** 对cell的内容做控制（隐藏开始和分享按钮） */
-(void)setIndexPath:(NSIndexPath*)indexPath count:(NSInteger)count{
    if (indexPath.row==count-1) {
        self.shareButton.hidden =NO;
        self.startButton.hidden=NO;
    }else{
        self.shareButton.hidden=YES;
        self.startButton.hidden =YES;
    }
}
@end
